<html>
<head><meta charset="utf-8"><title>Quasy quoting for assists · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html">Quasy quoting for assists</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215762962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215762962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215762962">(Nov 05 2020 at 19:34)</a>:</h4>
<p>So I started tinkering around with a proc-macro for this and I made some good progress, though I do not know whether the approach I have so far will work out for everything in the end. A snippet I was able to replace with it now:</p>
<div class="codehilite" data-code-language="Diff"><pre><span></span><code>fn extract_struct_def(
    rewriter: &amp;mut SyntaxRewriter,
    enum_: &amp;ast::Enum,
    variant_name: ast::Name,
    variant_list: &amp;ast::TupleFieldList,
    start_offset: &amp;SyntaxElement,
    visibility: Option&lt;ast::Visibility&gt;,
) -&gt; Option&lt;()&gt; {
<span class="gd">-    let variant_list = make::tuple_field_list(</span>
<span class="gd">-        variant_list</span>
<span class="gd">-            .fields()</span>
<span class="gd">-            .flat_map(|field| Some(make::tuple_field(Some(make::visibility_pub()), field.ty()?))),</span>
<span class="gd">-    );</span>
<span class="gd">-</span>
<span class="gd">-    rewriter.insert_before(</span>
<span class="gd">-        start_offset,</span>
<span class="gd">-        make::struct_(visibility, variant_name, None, variant_list.into()).syntax(),</span>
<span class="gd">-    );</span>
<span class="gi">+    let tys = variant_list.fields().flat_map(|field| field.ty());</span>
<span class="gi">+    let struct_ = make_quote::quote! {</span>
<span class="gi">+        #visibility struct #variant_name( #(pub #tys),* );</span>
<span class="gi">+    };</span>
<span class="gi">+</span>
<span class="gi">+    rewriter.insert_before(start_offset, struct_.syntax());</span>
    rewriter.insert_before(start_offset, &amp;make::tokens::blank_line());

    if let indent_level @ 1..=usize::MAX = IndentLevel::from_node(enum_.syntax()).0 as usize {
        rewriter
            .insert_before(start_offset, &amp;make::tokens::whitespace(&amp;" ".repeat(4 * indent_level)));
    }
    Some(())
}
</code></pre></div>
<p>The invocation there specifically:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">make_quote</span>::<span class="n">quote</span><span class="o">!</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="err">#</span><span class="n">visibility</span><span class="w"> </span><span class="k">struct</span> <span class="err">#</span><span class="n">variant_name</span><span class="p">(</span><span class="w"> </span><span class="err">#</span><span class="p">(</span><span class="k">pub</span><span class="w"> </span><span class="err">#</span><span class="n">tys</span><span class="p">),</span><span class="o">*</span><span class="w"> </span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>expands to</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">make</span>::<span class="n">struct_</span><span class="p">(</span><span class="w"></span>
<span class="w">    </span><span class="n">visibility</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">variant_name</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="nb">None</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="n">ast</span>::<span class="n">FieldList</span>::<span class="n">TupleFieldList</span><span class="p">(</span><span class="n">make</span>::<span class="n">tuple_field_list</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span>::<span class="n">itertools</span>::<span class="n">__std_iter</span>::<span class="nb">IntoIterator</span>::<span class="n">into_iter</span><span class="p">(</span><span class="n">tys</span><span class="p">)</span><span class="w"></span>
<span class="w">            </span><span class="p">.</span><span class="n">map</span><span class="p">(</span><span class="o">|</span><span class="p">(</span><span class="n">tys</span><span class="p">)</span><span class="o">|</span><span class="w"> </span><span class="n">make</span>::<span class="n">tuple_field</span><span class="p">(</span><span class="nb">Some</span><span class="p">(</span><span class="n">make</span>::<span class="n">visibility_pub</span><span class="p">()),</span><span class="w"> </span><span class="n">tys</span><span class="p">)),</span><span class="w"></span>
<span class="w">    </span><span class="p">)),</span><span class="w"></span>
<span class="p">);</span><span class="w"></span>
</code></pre></div>



<a name="215769162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215769162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215769162">(Nov 05 2020 at 20:24)</a>:</h4>
<p>So this currently relies on <code>make</code> to typecheck things, but i imagine ideally this should typecheck on its own and then just emit a string that gets parsed to an ast?</p>



<a name="215831568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215831568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215831568">(Nov 06 2020 at 11:08)</a>:</h4>
<blockquote>
<p>So this currently relies on make to typecheck things, but i imagine ideally this should typecheck on its own and then just emit a string that gets parsed to an ast?</p>
</blockquote>
<p>Not really, ideally, we should remove strings from <code>make</code></p>



<a name="215831600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215831600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215831600">(Nov 06 2020 at 11:08)</a>:</h4>
<p>Strings are just a way to quicly implement AST construction without too much work</p>



<a name="215831709"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215831709" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215831709">(Nov 06 2020 at 11:10)</a>:</h4>
<p>Ideally, we should build AST directly from tree pieces, bypassing the parser</p>



<a name="215832015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215832015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215832015">(Nov 06 2020 at 11:13)</a>:</h4>
<p>I am not entirely sure how to square this with quasi-quoting :-) An austronautical approach would be to run rust-analyzer's parser at compile time to allow building anything</p>



<a name="215832069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215832069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215832069">(Nov 06 2020 at 11:13)</a>:</h4>
<p>A more down-to-earth approach would be to special-case everything. Basically, the whole of <code>make</code> API, but with a nicer syntax</p>



<a name="215832352"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215832352" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215832352">(Nov 06 2020 at 11:16)</a>:</h4>
<p>Both approaches, however, are compatible with building AST from trees.</p>
<p><span class="user-mention" data-user-id="300586">@veykril</span> you might also look at <a href="https://github.com/apple/swift/tree/main/lib/Syntax">https://github.com/apple/swift/tree/main/lib/Syntax</a> for inpsiration</p>



<a name="215863782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215863782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215863782">(Nov 06 2020 at 15:48)</a>:</h4>
<p>Just took a look at the swift stuff. Were there any big differences between swifts syntax trees and rowan?</p>



<a name="215863944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215863944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215863944">(Nov 06 2020 at 15:49)</a>:</h4>
<p>I suppose using the <code>make</code> api is the ideal choice to make here though what I always wondered about it is that internally all make functions just display and then reparse the displayed string, doesn't this go heavily against the tree interning/sharing of what this architecture is kind of about? Since we discard all the parts passed to make by reparsing them from a string</p>



<a name="215866317"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215866317" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215866317">(Nov 06 2020 at 16:04)</a>:</h4>
<p>Yes, rowan is almost 1-1 copy of libsyntax. There are two big differences</p>



<a name="215866334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215866334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215866334">(Nov 06 2020 at 16:04)</a>:</h4>
<p>well, more than two :)</p>



<a name="215866541"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215866541" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215866541">(Nov 06 2020 at 16:06)</a>:</h4>
<p><strong>handling of trivia</strong>. In swift syntax, trivia are attached to non-trivial tokens. </p>
<p>That is, every node has a statically fixed layout, and things like <code>struct /* many*/ /* separate */ /*comment* F /*nodes*/ /*here*/;</code> are handled by attaching a vec of comments/whitespace to a fixed non-ws token</p>



<a name="215866604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215866604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215866604">(Nov 06 2020 at 16:06)</a>:</h4>
<p>I am actually warming up to this idea, and think that it <em>might</em> make sense to transition rust-analyzer to this representation</p>



<a name="215868634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215868634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215868634">(Nov 06 2020 at 16:21)</a>:</h4>
<p><strong>handling of collections.</strong> Because swift supports only nodes with fixed layout, all collection nodes are homogeneous. </p>
<p>Ie, if in Rust, for <code>{foo: i32, bar: f64}</code> we put <code>{}</code> and the fields into tht same node, swift will introduce an intermediate node here</p>



<a name="215868664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215868664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215868664">(Nov 06 2020 at 16:21)</a>:</h4>
<p>one node will hold three elements: two braces and field list</p>



<a name="215868694"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215868694" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215868694">(Nov 06 2020 at 16:21)</a>:</h4>
<p>the field list node will hold N identical nodes (fields)</p>



<a name="215868843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215868843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215868843">(Nov 06 2020 at 16:22)</a>:</h4>
<p><strong>thread safety</strong> swift uses Arcs, which means arc bumps during traversal of sytnax nodes. rust-analyzer uses Rc, which should be much cheaper</p>



<a name="215872226"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215872226" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215872226">(Nov 06 2020 at 16:47)</a>:</h4>
<p>Ah I see, I also just reread <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/syntax.md">https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/syntax.md</a> so I do see the differences you mentioned there as well now.</p>



<a name="215872323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215872323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215872323">(Nov 06 2020 at 16:48)</a>:</h4>
<p>Regarding <code>make</code> stringifying and reparsing the string as a node, is it meant to stay like this in the future? Im just asking out of curiosity.</p>



<a name="215873998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215873998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215873998">(Nov 06 2020 at 17:01)</a>:</h4>
<p>Oup, sorry, forgot to answer that one</p>



<a name="215874004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215874004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215874004">(Nov 06 2020 at 17:01)</a>:</h4>
<p>No, just the opposite</p>



<a name="215874057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215874057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215874057">(Nov 06 2020 at 17:01)</a>:</h4>
<p>stringification is a temp hack, and we totally should replace it with assembling trees from bits and pieces</p>



<a name="215874160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215874160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215874160">(Nov 06 2020 at 17:02)</a>:</h4>
<p>The specific case where stringification falls down is that, if a source node has a syntax error, the stringified&amp;reparsed node might not reparse into the desired node type</p>



<a name="215884483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215884483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215884483">(Nov 06 2020 at 18:22)</a>:</h4>
<p>Oh that does seem like a problem, so I take the sole reason <code>make</code> works the way it does currently is because it was simple to do it like that for now?</p>



<a name="215884609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215884609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215884609">(Nov 06 2020 at 18:23)</a>:</h4>
<p>From the looks of it, emitting <code>make</code> calls seems to be the best choice here nevertheless, since I dont think the make will change much then should the stringify hack disappear at some point, so I guess my proc-macro prototype is already on a good track like this.</p>



<a name="215890342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215890342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215890342">(Nov 06 2020 at 19:08)</a>:</h4>
<p>yeah, make should be phased away, but its ok to use it today</p>



<a name="215890356"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215890356" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215890356">(Nov 06 2020 at 19:08)</a>:</h4>
<p>However, an alternative would be to use ungrammar directly</p>



<a name="215890386"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215890386" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215890386">(Nov 06 2020 at 19:08)</a>:</h4>
<p><a href="https://github.com/rust-analyzer/ungrammar/blob/eb7e474d641fdb5210318479696cb7b362190cfd/rust.ungram#L164-L169">https://github.com/rust-analyzer/ungrammar/blob/eb7e474d641fdb5210318479696cb7b362190cfd/rust.ungram#L164-L169</a></p>



<a name="215890416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215890416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215890416">(Nov 06 2020 at 19:09)</a>:</h4>
<p>It contains all the info necessary to build a tree from pieces.</p>



<a name="215913543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215913543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215913543">(Nov 06 2020 at 22:46)</a>:</h4>
<p>What would replace make? I would believe the surface api would look the same no?</p>



<a name="215913570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215913570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215913570">(Nov 06 2020 at 22:47)</a>:</h4>
<p>I imagine if anything it should in the end be generated to some degree like most of the ast stuff?</p>



<a name="215913654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215913654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215913654">(Nov 06 2020 at 22:48)</a>:</h4>
<p>Yeah, I mean, the impl should change</p>



<a name="215913686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215913686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215913686">(Nov 06 2020 at 22:48)</a>:</h4>
<p>the API I think looks about right, although it's plausible that we can replace all of it with just <code>ast::make!</code> macro</p>



<a name="215913706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215913706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215913706">(Nov 06 2020 at 22:48)</a>:</h4>
<p>And yeah, it should be generated from ungrmmar</p>



<a name="215914447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/215914447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#215914447">(Nov 06 2020 at 22:56)</a>:</h4>
<p>Alright, now I'm grasping the full situation regarding this I believe, thanks for the thorough explanation <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="216091900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/216091900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#216091900">(Nov 09 2020 at 14:37)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span> have you seen <a href="https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/syntax-transformation">https://docs.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/get-started/syntax-transformation</a> ? This is an interesting doc to study re tree edits</p>



<a name="216093421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/216093421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#216093421">(Nov 09 2020 at 14:47)</a>:</h4>
<p>No I haven't. Will take a look it later <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<a name="217071513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/217071513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#217071513">(Nov 17 2020 at 22:20)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span>  just randomly cc'ing you to take a look at this fun API from roslyn: <a href="https://github.com/dotnet/roslyn/blob/4d8cada2584dd2e58b391c32c84f10f29442fdde/src/Workspaces/Core/Portable/Editing/SyntaxEditor.cs#L125-L141">https://github.com/dotnet/roslyn/blob/4d8cada2584dd2e58b391c32c84f10f29442fdde/src/Workspaces/Core/Portable/Editing/SyntaxEditor.cs#L125-L141</a></p>
<p>I wonder if this "The node passed into the compute function includes changes from prior edits" bit could be used to make SyntaxRewriter infra less horrible..</p>



<a name="217077698"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/217077698" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#217077698">(Nov 17 2020 at 23:28)</a>:</h4>
<p>That looks does look interesting. Good question whether that could somehow clean up SyntaxRewriter, though I'm not really sure how that could be applied to make it less of a mess</p>



<a name="217078342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Quasy%20quoting%20for%20assists/near/217078342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Quasy.20quoting.20for.20assists.html#217078342">(Nov 17 2020 at 23:37)</a>:</h4>
<p>Maybe I just can't think of any the use cases for this function, though i also don't really have in mind right now how we use SyntaxRewriter, will have to take a look at that again</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>